package org.casscommunity.sights.client.gin;

import org.casscommunity.sights.client.mvp.AppActivityMapper;
import org.casscommunity.sights.client.mvp.AppPlaceHistoryMapper;
import org.casscommunity.sights.client.view.DefaultEditPlaceView;
import org.casscommunity.sights.client.view.DefaultHomeView;
import org.casscommunity.sights.client.view.DefaultPlaceView;
import org.casscommunity.sights.client.view.EditPlaceView;
import org.casscommunity.sights.client.view.HomeView;
import org.casscommunity.sights.client.view.PlaceView;
import org.casscommunity.sights.shared.place.Home;

import com.google.gwt.activity.shared.ActivityManager;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.event.shared.SimpleEventBus;
import com.google.gwt.inject.client.AbstractGinModule;
import com.google.gwt.place.shared.PlaceController;
import com.google.gwt.place.shared.PlaceHistoryHandler;
import com.google.gwt.place.shared.PlaceHistoryMapper;
import com.google.inject.Provides;
import com.google.inject.Singleton;

public class AppGinModule extends AbstractGinModule {

	@Override
	protected void configure() {
		bind(EventBus.class).to(SimpleEventBus.class).in(Singleton.class);
		bind(ActivityMapper.class).to(AppActivityMapper.class);
		bind(PlaceHistoryMapper.class).to(AppPlaceHistoryMapper.class).in(Singleton.class);

		// Views
		bind(HomeView.class).to(DefaultHomeView.class).in(Singleton.class);
		bind(PlaceView.class).to(DefaultPlaceView.class).in(Singleton.class);
		bind(EditPlaceView.class).to(DefaultEditPlaceView.class).in(Singleton.class);
	}
	
	@Provides @Singleton
	ActivityManager provideActivityManager(ActivityMapper activityMapper, EventBus eventBus) {
		return new ActivityManager(activityMapper, eventBus);
	}
	
	@Provides @Singleton
	PlaceController providePlaceController(EventBus eventBus) {
		return new PlaceController(eventBus);
	}
	
	@Provides @Singleton
	PlaceHistoryHandler providePlaceHistoryHandler(PlaceHistoryMapper historyMapper, PlaceController placeController, EventBus eventBus) {
		PlaceHistoryHandler historyHandler = new PlaceHistoryHandler(historyMapper);
        historyHandler.register(placeController, eventBus, new Home());
		return historyHandler;
	}

}
